package com.anjie.powerproject.repository;

import com.anjie.powerproject.entity.Device;
import com.anjie.powerproject.pojo.CustomAtlasDevice;
import com.anjie.powerproject.pojo.CustomDevice;
import com.anjie.powerproject.strategy.pojo.device.BaseDevice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface DeviceRepository extends JpaRepository<Device, Integer> {

    @Query(nativeQuery = true ,value = "select * from device where type_id = ?1")
    List<Device> selectDevicesByTypeId(Integer typeId);

    @Query(nativeQuery = true, value = "select * from device where dev_code = ?1 limit 1")
    Device selectDeviceByDevCode(String code);

    @Query(value = "select new com.anjie.powerproject.pojo.CustomDevice(d.deviceId,d.deviceName) from Device d")
    List<CustomDevice> selectAllDevices();

    List<Device> findDevicesByDeviceNameEquals(String deviceName);

    @Query(value = "select new com.anjie.powerproject.pojo.CustomDevice(d.deviceId,d.deviceName) from Device d where d.deviceId = ?1")
    CustomDevice selectCustomDevice(Integer deviceId);

    @Query(nativeQuery = true, value = "select * from device where device_id in (select distinct device_id from graph_dev where graph_id = ?1)")
    List<Device> findDevicesByGraphId(Integer graphId);
}
